package com.we823.project.model.product;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.we823.project.common.web.status.TaskStatus;
import com.we823.project.core.web.WebConstants;
import com.we823.project.model.BaseModelWithDate;
import com.we823.project.model.UserModel;
import com.we823.utils.web.DateUtil;

/**
 * 生产任务
 * @author ZhangYinxian
 *
 */
@Entity
@Table(name="we_product_task")
public class ProductTaskModel extends BaseModelWithDate {
	
	private static final long serialVersionUID = 1L;

	private String code;

	private String name;

	@Column(name="plan_detail_id")
	private Integer planDetailId=0;
	
	@JSONField(serialzeFeatures=SerializerFeature.DisableCircularReferenceDetect)
	@Transient
	private PlanDetailModel planDetail;
	
	@Enumerated(EnumType.STRING)
	private TaskStatus status=TaskStatus.NoProduct;

	@Column(name="user_id")
	private Integer userId;
	
	@Transient
	private UserModel user;

	@JSONField(format="yyyy-MM-dd HH:mm:ss")
	@DateTimeFormat(pattern=WebConstants.DATE_PATTERN)
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="start_time")
	private Date starttime;

	@JSONField(format="yyyy-MM-dd HH:mm:ss")
	@DateTimeFormat(pattern=WebConstants.DATE_PATTERN)
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="finish_time")
	private Date finishtime;

	@Column(name="need_total")
	private float needTotal=0f;

	@Column(name="final_total")
	private float finalTotal=0f;
	
	@Transient
	private String cardname;
	
	@Transient
	private String countTime;
	
	public ProductTaskModel() {
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Date getFinishtime() {
		return this.finishtime;
	}

	public void setFinishtime(Date finishtime) {
		this.finishtime = finishtime;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getStarttime() {
		return this.starttime;
	}

	public void setStarttime(Date starttime) {
		this.starttime = starttime;
	}

	public UserModel getUser() {
		return this.user;
	}

	public void setUser(UserModel user) {
		this.user = user;
	}

	public TaskStatus getStatus() {
		return status;
	}

	public void setStatus(TaskStatus status) {
		this.status = status;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Integer getPlanDetailId() {
		return planDetailId;
	}

	public void setPlanDetailId(Integer planDetailId) {
		this.planDetailId = planDetailId;
	}

	public PlanDetailModel getPlanDetail() {
		return planDetail;
	}

	public void setPlanDetail(PlanDetailModel planDetail) {
		this.planDetail = planDetail;
	}

	public float getNeedTotal() {
		return needTotal;
	}

	public void setNeedTotal(float needTotal) {
		this.needTotal = needTotal;
	}

	public float getFinalTotal() {
		return finalTotal;
	}

	public void setFinalTotal(float finalTotal) {
		this.finalTotal = finalTotal;
	}

	public String getCardname() {
		return cardname;
	}

	public void setCardname(String cardname) {
		this.cardname = cardname;
	}
	
	public String getCountTime() {
		if(starttime!=null && finishtime!=null) {
			return DateUtil.calculate(starttime, finishtime);
		}
		return "";
	}
	
	
}